package com.yonyou.pmclouds.measureindex.service.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.businessobject.util.BulkDataSplitUtils;
import com.yonyou.pmclouds.measureindex.entity.MeasureIndexHistoryVO;
import com.yonyou.pmclouds.measureindex.mapper.MeasureIndexHisMapper;
import com.yonyou.pmclouds.measureindex.service.rmiitf.MeasureIndexHisQuery;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

@Service(interfaceClass = MeasureIndexHisQuery.class,version = ApplicationConsts.APPLICATION_VERSION)
public class MeasureIndexHisQueryImpl implements MeasureIndexHisQuery {

    @Autowired
    private MeasureIndexHisMapper mapper;
    @Override
    public Map<String, List<MeasureIndexHistoryVO>> queryByPkProgressHiss(String[] pkProgressHiss) {

        if(pkProgressHiss == null || pkProgressHiss.length ==0) return null;

        HashSet<String> pkSet = new HashSet<>();

        Collections.addAll(pkSet, pkProgressHiss);

        MeasureIndexHistoryVO[] measureIndexHistoryVOS = mapper.selectMeasureIndexVOSByProgressHiss(BulkDataSplitUtils.getSplitDataSet(pkSet));

        HashMap<String, List<MeasureIndexHistoryVO>> data = new HashMap<>();

        for (MeasureIndexHistoryVO measureIndexHistoryVO : measureIndexHistoryVOS) {
            String pkProgressHis = measureIndexHistoryVO.getPkProgressHis();

            List<MeasureIndexHistoryVO> measureIndexVOList = data.get(pkProgressHis);

            if(measureIndexVOList == null) measureIndexVOList = new ArrayList<MeasureIndexHistoryVO>();

            measureIndexVOList.add(measureIndexHistoryVO);

            data.put(pkProgressHis,measureIndexVOList);
        }

        return data;
    }

    @Override
    public List<MeasureIndexHistoryVO> queryByPkScheduleItems(String[] pkScheduleItems) throws BusinessException {
        return null;
    }
}
